const express = require("express");
const cors = require("cors");
const app = express();
// 映射public目录中的静态资源
const path = require("path");
const staticRoot = path.resolve(__dirname, "../public");
app.use(express.static(staticRoot));

// const whiteList = ["null", ""];

//解决跨域
app.use(
  cors({
    credentials: true,
  })
);

// 解析 application/x-www-form-urlencoded 格式的请求体
// app.use(express.urlencoded({extended:true}))

//解析application/json格式的请求体
app.use(express.json());

app.use("/api/article", require("./api/article"));
app.use("/api/type", require("./api/type"));
app.use("/api/tag", require("./api/tag"));
app.use("/api/contact", require("./api/contact"));
app.use("/api/adSpace", require("./api/adSpace"));
app.use("/api/upload", require("./api/upload"));

//处理错误的中间件
app.use(require("./errorMiddleware"));

const port = 5008;
app.listen(port, () => {
  console.log(`localhost:${port}`);
});
